home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / eyes.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  4KB  |  187 lines

  1. /***   [eyes.c]
  2. *
  3. *    「目」ウィンドウ 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <stdio.h>
  10. #include <math.h>
  11. #include "graph.h"
  12. #include "mos.h"
  13. #include "window.h"
  14. #include "icn.h"
  15. #include "others.h"
  16.  
  17. #define WH_CAN        1
  18. #define WH_TITLE    2
  19. #define WH_OTHER    0
  20.  
  21. extern int    PAL_Black;
  22. static int    wx, wy;
  23. static int    pex1, pey1, pex2, pey2;
  24.  
  25. static void    Draw_window(void);
  26. static int    Where(int, int);
  27. static void eye(void);
  28. static int cal(int, int, int *, int *);
  29.  
  30. void WIND_eyes(void) {
  31.     int        ret = 0;
  32.     struct RECT    a, b;
  33.     
  34.     wx = 205;
  35.     wy = 165;
  36.     a.x1 = 319;    a.y1 = 259;
  37.     a.x2 = 320;    a.y2 = 260;
  38.     b.x1 = wx;    b.y1 = wy;
  39.     b.x2 = wx + 229;    b.y2 = wy + 150;
  40.     afterImage(&a, &b);
  41.     
  42.     Draw_window();
  43.     pex1 = 1000;
  44.     pey1 = 1000;
  45.     pex2 = 1000;
  46.     pey2 = 1000;
  47.     while (!ret) {
  48.         char    mb;
  49.         int        mx, my, wh;
  50.         
  51.         CLOCK(0);
  52.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1)) {
  53.             eye();
  54.             continue;
  55.         }
  56.         
  57.         if ((wh = Where(mx, my)) == WH_CAN) {
  58.             if (Button(wx + 6, wy + 6, wx + 25, wy + 25))
  59.                 ret = 1;
  60.         } else if (wh == WH_TITLE) {
  61.             struct RECT    s, w;
  62.             
  63.             w.x1 = wx;    w.y1 = wy;
  64.             w.x2 = wx + 229;    w.y2 = wy + 150;
  65.             s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  66.             if (dragWindow(mx, my, &w, &s, 0, 0)) {
  67.                 wx = w.x1;    wy = w.y1;
  68.                 MOS_disp(0);
  69.                 EGB_cls(0);
  70.                 MOS_disp(1);
  71.                 Draw_window();
  72.                 pex1 = 1000;
  73.                 pey1 = 1000;
  74.                 pex2 = 1000;
  75.                 pey2 = 1000;
  76.             }
  77.         } else {
  78.             while (MOS_rdpos(&mb, &mx, &my), mb & 1)
  79.                 eye();
  80.         }
  81.     }
  82.     
  83.     return;
  84. }
  85.  
  86. static void Draw_window(void) {
  87.     short    el[4];
  88.     struct opnwin_t    opw;
  89.     
  90.     opw.title = "Eyes";
  91.     opw.x1 = wx;
  92.     opw.y1 = wy;
  93.     opw.x2 = opw.x1 + 229;
  94.     opw.y2 = opw.y1 + 150;
  95.     opw.shdw = 1;
  96.     opw.canb = 1;
  97.     opw.nopt = 0;
  98.     opw.wopt = NULL;
  99.     opw.expb = 0;
  100.     opw.ord = 0;
  101.     MOS_disp(0);
  102.     drawWindow(&opw);
  103.     
  104.     EGB_color(EGB_work, EGB_COL_FORE, PAL_Black);
  105.     EGB_color(EGB_work, EGB_COL_PAINT, 15);
  106.     EGB_paintMode(EGB_work, 0x022);
  107.     
  108.     EGB_pen(EGB_work, 0);
  109.     EGB_penSize(EGB_work, 8);
  110.     el[0] = wx + 65;
  111.     el[1] = wy + 86;
  112.     el[2] = 40;
  113.     el[3] = 46;
  114.     EGB_ellipse(EGB_work, (char *)el);
  115.     el[0] = wx + 165;
  116.     el[1] = wy + 86;
  117.     el[2] = 40;
  118.     el[3] = 46;
  119.     EGB_ellipse(EGB_work, (char *)el);
  120.     EGB_penSize(EGB_work, 1);
  121.     MOS_disp(1);
  122. }
  123.  
  124. static int Where(int x, int y) {
  125.     int        ret;
  126.     
  127.     x -= wx;
  128.     y -= wy;
  129.     if (5 < x && x < 26 && 5 < y && y < 26)
  130.         ret = WH_CAN;
  131.     else if (26 < x && x < 224 && 5 < y && y < 26)
  132.         ret = WH_TITLE;
  133.     else
  134.         ret = WH_OTHER;
  135.     
  136.     return ret;
  137. }
  138.  
  139. static void eye(void) {
  140.     int        mx, my, ex, ey;
  141.     char    mb;
  142.     
  143.     MOS_rdpos(&mb, &mx, &my);
  144.     EGB_penSize(EGB_work, 16);
  145.     
  146.     cal(mx - (wx + 65), my - (wy + 86), &ex, &ey);
  147.     if (pex1 != ex || pey1 != ey) {
  148.         MOS_disp(0);
  149.         EGB_pointset(pex1 + (wx + 65), pey1 + (wy + 86), 15);
  150.         EGB_pointset(ex + (wx + 65), ey + (wy + 86), PAL_Black);
  151.         MOS_disp(1);
  152.         pex1 = ex;
  153.         pey1 = ey;
  154.     }
  155.     cal(mx - (wx + 165), my - (wy + 86), &ex, &ey);
  156.     if (pex2 != ex || pey2 != ey) {
  157.         MOS_disp(0);
  158.         EGB_pointset(pex2 + (wx + 165), pey2 + (wy + 86), 15);
  159.         EGB_pointset(ex + (wx + 165), ey + (wy + 86), PAL_Black);
  160.         MOS_disp(1);
  161.         pex2 = ex;
  162.         pey2 = ey;
  163.     }
  164.     
  165.     EGB_penSize(EGB_work, 1);
  166. }
  167.  
  168. #define POW(x)    ((x) * (x))
  169. static int cal(int mx, int my, int *ex, int *ey) {
  170.     int        ret;
  171.     float    k;
  172.     
  173.     if (POW((float)mx) / POW(24.0) + POW((float)my) / POW(27.6) <= 1.0) {    /* 27.6 == 40 * .6 * 1.15   24 == 40 * .6 */
  174.         ret = 1;
  175.         *ex = mx;
  176.         *ey = my;
  177.     } else {
  178.         ret = 0;
  179.         k = sqrt(1.0 / (POW((float)mx / 24.0) + POW((float)my / 27.6)));
  180.         *ex = k * mx;
  181.         *ey = k * my;
  182.     }
  183.     
  184.     return ret;
  185. }
  186. #undef POW
  187.